<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>Gestalt Sample: Medium Particles - Python</title>

    <script src="../../js/jquery.js" type="text/javascript"></script>

    <script src="../../js/gestalt.js" type="text/javascript"></script>

</head>
<body >

<script language="python">

# imports
from System import * # for Convert
from System.Windows import * # for NameProperty
from System.Windows.Shapes import * # exposes Rectangle to scope since not added by default
from System.Windows.Media.Animation import * # exposes Storyboard
#from System.Windows.Media.Imaging import * # for bitmap
from System.Diagnostics import * # enables outputing to a debug window
from System.Net import * # for WebClient
from System.Windows.Resources import * # for WebClient
from System.Windows.Markup import * # for XamlReader

# localize
layoutRoot = me.LayoutRoot

# locals
_dot = None

#
# define class that procedurally creates Tile code instead of XAML
#
class Dot(UserControl): # inherits from UserControl
    def __init__(self, xaml):
        self.xaml = xaml
    
        ### CREATE INSTANCE VARIABLES ###
        self.Content = XamlReader.Load(self.xaml)
        
        def sbDrop_Completed(sender, e): # Storyboard is define in XAML
            self.Parent.Children.Remove(self);
            
        self.Content.sbDrop.Completed += sbDrop_Completed
            
        self.Content.sbDrop.Begin();
        
        
    ### X property ###
    def SetX(self, value):
        self.SetValue(Canvas.LeftProperty, Convert.ToDouble(value))
    def GetX(self):
        return self.GetValue(Canvas.LeftProperty)
    X = property(GetX, SetX)
    
    ### Y property ###  
    def SetY(self, value):
        self.SetValue(Canvas.TopProperty, Convert.ToDouble(value))
    def GetY(self):
        return self.GetValue(Canvas.TopProperty)
    Y = property(GetY, SetY)
    
#
# Define event handlers before they are referenced below
#
def DotLoaded(sender, e):
    global _dot
    _dot = e.Result
    Main()
    
def Page_MouseMove(sender, e):
    global layoutRoot
    global _dot
    d = Dot(_dot)
    d.X = e.GetPosition(layoutRoot).X;
    d.Y = e.GetPosition(layoutRoot).Y;
    layoutRoot.Children.Add(d);
    
#
# define methods
#
def LoadDot():
    client = WebClient()
    client.DownloadStringCompleted += DotLoaded
    client.DownloadStringAsync(Uri("../samples/particles/dot2.xaml", UriKind.RelativeOrAbsolute))
    
def Main():
    layoutRoot.MouseMove += Page_MouseMove 

    
# first thing load dependencies
LoadDot()

</script>

    <!-- This isn't a part of the sample, but a link back to the Gestalt site -->
<div id="upsell" style="color:#fff; font-size: 13px; font-family:'Lucida Grande','Lucida Sans Unicode',Helvetica,Arial,Lucida,Verdana,sans-serif; margin-bottom: 30px;">
    <a href="http://www.visitmix.com/labs/gestalt/samples/" style="background-color: #000; color: #fff; display: block; text-decoration: none;" onmouseover="this.style.color='#000'; this.style.background='#ccc'" onmouseout="this.style.color='#fff'; this.style.background='#000'">
		<span style="display:block; padding: 8px; text-align:center;">&laquo; Check out other samples on the Gestalt web site</span>
	</a>
</div>
    
<!-- The following commented line of code is equivalent to the inline XAML
     and we recommend doing it this way. Only caveat, if you link to a XAML
     file, you'll be able to view the page correctly only through a server 
     (e.g. apache or IIS) because of security sandbox reasons. -->
    
    <!--<xml src="page2.xaml" id="page" class="xaml" width="600" height="300" style="display:none;"></xml>-->
    
    <xml id="page" class="xaml" width="600" height="300" style="display:none;">
    
        <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="600" Height="300">
          <Canvas x:Name="LayoutRoot" Background="#333333">
            <TextBlock Canvas.Left="10" Canvas.Top="10" Text="Move the mouse on the stage to draw your dots..." Foreground="White"></TextBlock>
          </Canvas>
        </UserControl>
    
    </xml>
    
</body>
</html>



    